﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.Win32;
using Microsoft.SharePoint.Administration;
using System.IO;
using System.Reflection;

namespace SPVisualDev.Services
{
    internal class Common
    {
        public static Dictionary<string, string> GetPropertiesFromObject(object Object)
        {
            Dictionary<string, string> properties = new Dictionary<string, string>();

            foreach (PropertyInfo pInfo in Object.GetType().GetProperties())
            {
                try
                {
                    object v = pInfo.GetValue(Object, null);
                    if (v != null)
                    {
                        properties.Add(pInfo.Name, v.ToString());
                    }
                    else
                    {
                        properties.Add(pInfo.Name, string.Empty);
                    }
                }
                catch
                {
                }
            }

            return properties;
        }

        public static string GetXmlAttribute(XmlElement element, string AttributeName)
        {
            string ret = string.Empty;
            foreach (XmlAttribute attribute in element.Attributes)
            {
                if (string.Compare(attribute.Name, AttributeName, true) == 0)
                {
                    ret = attribute.Value;
                    break;
                }
            }

            return ret;
        }
    }
}
